using System.Collections.Generic;
using System.Linq;
using TaskKernel.Domain.Services.Role;

namespace TaskKernel.Domain.Services.Permission
{
    public class DepartmentPermissions
    {
        private readonly ICollection<IPermission<DepartmentPermissions>> _permissions;

        public DepartmentPermissions(RoleEnum role,
                                     IEnumerable<IPermission<DepartmentPermissions>> permissions)
        {
            _permissions = permissions.ToList();
            Role = role;
        }

        public RoleEnum Role { get; protected set; }

        public virtual void AddPermissions(IPermission<DepartmentPermissions> permissions)
        {
            _permissions.Add(permissions);
        }

        public virtual Permissions GetPermissions()
        {
            foreach (var permission in _permissions)
            {
                Permissions permissions = permission.GetPermissions(this);
                if (!permissions.GetType().Equals(new Permissions().GetType()))
                    return permissions;
            }
            return new Permissions();
        }
    }
}